package kuang.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //    callable无法直接被Thread使用
        //    new Thread(new Runnable()).start();
        //    new Thread(new FutureTask<V>()).start();
        //    new Thread(new FutureTask<v>(Callable())).start();
        //构造器
        MyTread myTread = new MyTread();
        //适配类
        FutureTask futureTask = new FutureTask(myTread);

        new Thread(futureTask, "A").start();

        //返回结构在futureTask中的get中
        //这个get结果会产生阻塞！放到最后
        System.out.println(futureTask.get());

    }

}

class MyTread implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println("call");
        return 1024;
    }
}
